//
//  HDUserAccount.swift
//  HDSwfitWeibo
//
//  Created by wty on 16/4/11.
//  Copyright © 2016年 wty. All rights reserved.
//

import UIKit

class HDUserAccount: NSObject {
    //MARK  -用户密码数据
    //用户授权的唯一票据
    var access_token:String?
    //token 声明周期 单位是秒数
    var expires_in :NSTimeInterval = 0 {
        didSet {
            //设置辅助属性
            expiresDate = NSDate(timeIntervalSinceNow: expires_in)
        }
    }
    //过期时间
    var expiresDate :NSDate?
    //授权用户的uid
    var uid:String?
    
    //MARK  -首页的数据类型
    //用户昵称
    var screen_name:String?
    //用户头像地址
    var avatar_large:String?

    //kvc构造器字典转模型
    init(dict : [String: AnyObject]) {
        super.init()
        [self .setValuesForKeysWithDictionary(dict)]
    }
    override func setValue(value: AnyObject?, forKey key: String) {
        super.setValue(value, forKey: key)
        
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    //打印  用计算属性  就是只读属性
   override var description:String {
        get {
            return  "access_token: \(access_token), expires_in: \(expires_in), uid: \(uid), expiresDate: \(expiresDate)"
        }
    }
    //归档和解档
    //解档 读取
   required init(coder aDecoder :NSCoder) {
    access_token = aDecoder.decodeObjectForKey("access_token") as? String
    expires_in =  aDecoder.decodeDoubleForKey("expires_in")
    expiresDate = aDecoder.decodeObjectForKey("expiresDate") as? NSDate
    uid = aDecoder.decodeObjectForKey("uid") as? String
    screen_name = aDecoder.decodeObjectForKey("screen_name ") as? String
    avatar_large = aDecoder.decodeObjectForKey("avatar_large") as? String
    
    }
    //归档就是保存
    func encodeWithCoder (coder:NSCoder) {
        coder.encodeObject(access_token, forKey: "access_token")
        coder.encodeDouble(expires_in, forKey: "expires_in")
        coder.encodeObject(expiresDate, forKey: "expiresDate")
        coder.encodeObject(uid, forKey: "uid")
        coder.encodeObject(screen_name, forKey: "screen_name")
        coder.encodeObject(avatar_large, forKey: "avatar_large")
    }
    

}
